import * as PIXI from "pixi.js";
export default class PersonSprite {
  constructor() {
    this.loadTextures();
    this.container = new PIXI.AnimatedSprite(this.idleTexture);
    this.container.animationSpeed = 0.1;
    this.container.position.set(500, 415);
    this.container.play();
    this.hp = 10;
  }
  attack() {
    this.container.textures = this.attackTexture;
    this.container.loop = false;
    this.container.play();
    this.container.onComplete = () => {
      this.container.loop = true;
      this.idle();
    };
  }
  idle() {
    this.container.textures = this.idleTexture;
    this.container.loop = true;
    this.container.scale.x = 1;
    this.container.anchor.set(0, 0);
    this.container.play();
  }
  hurt() {
    this.container.textures = this.hurtTexture;
    this.container.loop = false;
    this.container.play();
    this.hp -= 1;
  }
  dead() {
    this.container.y += 36;
    this.container.textures = this.deadTexture;
    this.container.loop = false;
    this.container.play();
  }
  loadTextures() {
    const baseIdleTexture = PIXI.BaseTexture.from(
      "/public/person/Enchantress/Idle.png"
    );
    this.idleTexture = [];
    this.idleTexture.push(
      new PIXI.Texture(baseIdleTexture, new PIXI.Rectangle(37, 56, 55, 72))
    );
    this.idleTexture.push(
      new PIXI.Texture(baseIdleTexture, new PIXI.Rectangle(165, 56, 55, 72))
    );
    this.idleTexture.push(
      new PIXI.Texture(baseIdleTexture, new PIXI.Rectangle(292, 56, 55, 72))
    );
    this.idleTexture.push(
      new PIXI.Texture(baseIdleTexture, new PIXI.Rectangle(421, 56, 55, 72))
    );
    this.idleTexture.push(
      new PIXI.Texture(baseIdleTexture, new PIXI.Rectangle(549, 56, 55, 72))
    );

    const baseRunTexture = PIXI.BaseTexture.from(
      "/public/person/Enchantress/Run.png"
    );
    this.runTexture = [];
    this.runTexture.push(
      new PIXI.Texture(baseRunTexture, new PIXI.Rectangle(36, 59, 49, 69))
    );
    this.runTexture.push(
      new PIXI.Texture(baseRunTexture, new PIXI.Rectangle(165, 56, 55, 72))
    );
    this.runTexture.push(
      new PIXI.Texture(baseRunTexture, new PIXI.Rectangle(292, 56, 55, 72))
    );
    this.runTexture.push(
      new PIXI.Texture(baseRunTexture, new PIXI.Rectangle(421, 56, 55, 72))
    );
    this.runTexture.push(
      new PIXI.Texture(baseRunTexture, new PIXI.Rectangle(549, 56, 55, 72))
    );
    this.runTexture.push(
      new PIXI.Texture(baseRunTexture, new PIXI.Rectangle(678, 56, 55, 72))
    );
    this.runTexture.push(
      new PIXI.Texture(baseRunTexture, new PIXI.Rectangle(805, 56, 55, 72))
    );
    this.runTexture.push(
      new PIXI.Texture(baseRunTexture, new PIXI.Rectangle(933, 56, 55, 72))
    );

    const baseAttackTexture1 = PIXI.BaseTexture.from(
      "/public/person/Enchantress/Attack_2.png"
    );
    this.attackTexture = [];
    this.attackTexture.push(
      new PIXI.Texture(baseAttackTexture1, new PIXI.Rectangle(13, 58, 64, 70))
    );
    this.attackTexture.push(
      new PIXI.Texture(baseAttackTexture1, new PIXI.Rectangle(129, 58, 113, 70))
    );
    this.attackTexture.push(
      new PIXI.Texture(baseAttackTexture1, new PIXI.Rectangle(256, 58, 76, 70))
    );

    const baseHurtTexture = PIXI.BaseTexture.from(
      "/public/person/Enchantress/Hurt.png"
    );
    this.hurtTexture = [];
    this.hurtTexture.push(
      new PIXI.Texture(baseHurtTexture, new PIXI.Rectangle(30, 58, 64, 70))
    );
    this.hurtTexture.push(
      new PIXI.Texture(baseHurtTexture, new PIXI.Rectangle(156, 58, 64, 70))
    );

    const baseDeadTexture = PIXI.BaseTexture.from(
      "/public/person/Enchantress/Dead.png"
    );
    this.deadTexture = [];
    this.deadTexture.push(
      new PIXI.Texture(baseDeadTexture, new PIXI.Rectangle(27, 50, 59, 78))
    );
    this.deadTexture.push(
      new PIXI.Texture(baseDeadTexture, new PIXI.Rectangle(154, 50, 64, 78))
    );
    this.deadTexture.push(
      new PIXI.Texture(baseDeadTexture, new PIXI.Rectangle(282, 58, 70, 70))
    );
    this.deadTexture.push(
      new PIXI.Texture(baseDeadTexture, new PIXI.Rectangle(415, 87, 70, 41))
    );
    this.deadTexture.push(
      new PIXI.Texture(baseDeadTexture, new PIXI.Rectangle(540, 94, 74, 34))
    );
  }
}
